# @Author: Eric Ito
# @Date: 1/27/2009
# @Name: Project Euler Problem 19

"""
You are given the following information, but you may prefer to
do some research for yourself.

1 Jan 1900 was a Monday.
Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine.

A leap year occurs on any year evenly divisible by 4, but not on a
century unless it is divisible by 400. How many Sundays fell on the first
of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
"""

from util import DAYS
from util import MONTHS
from util import MONTH_DAYS
from util import LEAP_MONTH_DAYS

class DateCounter:
	def __init__(self,monthNum,date,year,dayNum):
		self.currMonth = MONTHS[monthNum]
		self.currDate = date
		self.currYear = year
		self.currDay = DAYS[dayNum]
		self.currDayNum = dayNum
		self.currMonthNum = monthNum
		
	def isLeapYear(self,yr):
		if yr % 100 == 0 and yr % 400 == 0:
			return True
		elif yr % 4 == 0 and not yr % 100 == 0:
			return True
		else:
			return False
			
	def increment(self):
		if self.isLeapYear(self.currYear):
			MTHS = LEAP_MONTH_DAYS
		else:
			MTHS = MONTH_DAYS
		if self.currDate == MTHS[self.currMonth]:
			# at the end of the month
			# reset day, increment month, increment year
			if self.currMonth == "DECEMBER":
				self.currMonth = "JANUARY"
				self.currMonthNum = 1
				self.currYear += 1
			else:
				self.currMonthNum = (self.currMonthNum % 12) + 1
				self.currMonth = MONTHS[self.currMonthNum]
			self.currDate = 1
		else:
			# not the end of month, just increment date,day of week
			self.currDate += 1
			
		#always incrememnt dayNum and day of week
		self.currDayNum = ((self.currDayNum ) % 7) + 1
		self.currDay = DAYS[self.currDayNum]


def pdebug(dc):
	#for i in range(60):
	print "day of month =",dc.currDate
	print "day of week =",dc.currDay
	print "numDay =",dc.currDayNum
	print "month =",dc.currMonth
	print "year =",dc.currYear
	print "monthNum =",dc.currMonthNum
	print "------"
		#dc.increment()
		

def main():
	dc = DateCounter(1,1,1900,1)
	#pdebug(dc)
	counter = 0

	while not (dc.currYear == 2000 and dc.currMonthNum == 12 and dc.currDate == 31):
		dc.increment()
		#pdebug(dc)
		if dc.currYear >= 1901:
			if dc.currDate == 1 and dc.currDay == "SUNDAY":
				counter += 1 

	print counter
	
if __name__ == '__main__':
    main()